package com.distributor.common;

import javax.servlet.ServletRequest;
import java.util.Enumeration;
import java.util.Map;
import java.util.TreeMap;

/**
 * 工具类
 *
 * @author zhanghaogao
 * @create 2017-11-15 上午10:07
 **/
public class ToolUtil {


    /**
     * 获取请求参数并转map
     *
     * @param request
     * @param prefix
     * @return
     */
    public static Map<String, Object> getParametersStartingWith(ServletRequest request) {

        Enumeration paramNames = request.getParameterNames();
        Map<String, Object> params = new TreeMap();
        while ((paramNames != null) && (paramNames.hasMoreElements())) {
            String paramName = (String) paramNames.nextElement();
            String values = request.getParameter(paramName);
            params.put(paramName, values);
        }
        return params;
    }
}
